package com.sg.business.work.handler;

import java.util.Map;

import org.eclipse.core.commands.Command;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;

import com.mobnut.db.model.PrimaryObject;
import com.sg.business.model.Work;
import com.sg.widgets.command.AbstractNavigatorHandler;
import com.sg.widgets.part.CurrentAccountContext;
import com.sg.widgets.part.RichInputDialog;
import com.sg.widgets.viewer.ViewerControl;

public class MarkWorkNote extends AbstractNavigatorHandler {

	@Override
	protected void execute(PrimaryObject selected, IWorkbenchPart part,
			ViewerControl vc, Command command,
			Map<String, Object> parameters, IStructuredSelection selection) {
		if (selected instanceof Work) {
			String note = ((Work) selected).getNote();
			if(note == null){
				note = "";
			}
			
			RichInputDialog ip = new RichInputDialog(part.getSite().getShell(), "Note", selected.getLabel(), note);
			if(RichInputDialog.OK == ip.open()){
				note = ip.getValue();
				((Work) selected).doSetNote(note,new CurrentAccountContext());
				vc.getViewer().update(selected, null);
			}
		}
	}


}
